package com.zhx.threadcoreknowledge.uncaughtexception;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author ：zhanghaixuan
 * @date ：Created in 2019-10-04 11:15
 * 用途         ： 自定义 UncaughtExceptionHandler
 */
public class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {

    private String name;

    public MyUncaughtExceptionHandler(String name) {
        this.name = name;
    }

    @Override
    public void uncaughtException(Thread t, Throwable e) {
        Logger logger = Logger.getAnonymousLogger();

        logger.log(Level.WARNING,"线程异常,终止啦 :" + t.getName(),e);

        System.out.println(name+"捕获了异常"+t.getName()+"异常:"+e);
    }
}
